package cn.zysuyuan.item.utils;


import cn.zysuyuan.item.entity.DeviceData;

/**
 * @author flypig
 * @version 1.0
 * @date 2019/10/14 23:07
 */
public class CaculateData {
    // 计算数据平均值
    public static Double CaculateData1(DeviceData sensorDevices){
        Double averageSoilHumidity;
        int size = 9;
        System.out.println("计算土壤湿度平均值");
        Double[] devicesData1 = new Double[size];
        devicesData1[0]=sensorDevices.gettSoilHumidity01();
        devicesData1[1]=sensorDevices.gettSoilHumidity02();
        devicesData1[2]=sensorDevices.gettSoilHumidity03();
        devicesData1[3]=sensorDevices.gettSoilHumidity04();
        devicesData1[4]=sensorDevices.gettSoilHumidity05();
        devicesData1[5]=sensorDevices.gettSoilHumidity06();
        devicesData1[6]=sensorDevices.gettSoilHumidity07();
        devicesData1[7]=sensorDevices.gettSoilHumidity08();
        devicesData1[8]=sensorDevices.gettSoilHumidity09();
        double num = 9.0;
        double sumSoilHumidity = 0.0;
        for (int i = 0; i < 9; i++) {
            if(devicesData1[i] != 0){
                sumSoilHumidity = sumSoilHumidity + devicesData1[i];
            }else{
                num--;
            }
        }
        System.out.println("++++++num:" + num);
        if ( num == 0 ){
            num = 1;
        }
        System.out.println("++++++num:" + num);
        averageSoilHumidity = sumSoilHumidity/num;
        return averageSoilHumidity;
    }

    public static Double CaculateData2(DeviceData sensorDevices){
        Double averageSoilTemperature;
        int size = 9;
        System.out.println("计算土壤温度平均值");
        Double[] devicesData2 = new Double[size];
        devicesData2[0]=sensorDevices.gettSoilTemperature01();
        devicesData2[1]=sensorDevices.gettSoilTemperature02();
        devicesData2[2]=sensorDevices.gettSoilTemperature03();
        devicesData2[3]=sensorDevices.gettSoilTemperature04();
        devicesData2[4]=sensorDevices.gettSoilTemperature05();
        devicesData2[5]=sensorDevices.gettSoilTemperature06();
        devicesData2[6]=sensorDevices.gettSoilTemperature07();
        devicesData2[7]=sensorDevices.gettSoilTemperature08();
        devicesData2[8]=sensorDevices.gettSoilTemperature09();
        double num = 9.0;
        double sumSoilTemperature = 0.0;
        for (int i = 0; i < 9; i++) {
            if(devicesData2[i] != 0){
                sumSoilTemperature = sumSoilTemperature + devicesData2[i];
            }else{
                num--;
            }
        }
        System.out.println("++++++num:" + num);
        if ( num == 0 ){
            num = 1;
        }
        System.out.println("++++++num:" + num);
        averageSoilTemperature = sumSoilTemperature/num;
        return  averageSoilTemperature;
    }
}
